﻿@using SDCloudSolution.SDCloud.Web.Utils
@using SDCloudSolution.SDCloud.Web.Models
@model SDCloudSolution.SDCloud.Web.Models.ModelRun.SpecificModelRunListViewModel

@{
    Layout = "~/Views/Shared/_AuthorizedLayout.cshtml";
    ViewBag.Title = "Model runs list";
}

@section scripts {
    <script src="~/Scripts/js/libs/require/require.js"></script>
    <script src="~/Scripts/app.js"></script>
    <script src="~/Scripts/sdCloud/run.history.view.js"></script>
}

<h1 class="page-header">
    <a href="@Url.Action(MVC.ModelRuns.List())">
        <img border="0" src="~/Content/left arrow.png" width="24" height="24"></a>

    Run history for @Html.ActionLink(Model.ModelName, MVC.Models.View(Model.ModelId))
</h1>

<div id="model-history">

    @if (Model.Items.Count > 0)
    {
        <table>
            <thead class="oj-table-header">
                <tr class="oj-table-header-row">
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                #
                            </div>
                        </div>
                    </th>
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                Queued
                            </div>
                        </div>
                    </th>
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                Time
                            </div>
                        </div>
                    </th>
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                Status
                            </div>
                        </div>
                    </th>
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                Details
                            </div>
                        </div>
                    </th>
                    <th class="oj-table-column-header-cell">
                        <div class="oj-table-column-header">
                            <div class="oj-table-column-header-text">
                                Results
                            </div>
                        </div>
                    </th>
                </tr>
            </thead>
            @foreach (var item in Model.Items)
                {
                <tbody class="oj-table-body">
                    <tr class="oj-table-body-row oj-table-hgrid-lines">
                        <td class="oj-table-data-cell oj-form-control-inherit">
                            @item.ModelRunId
                        </td>
                        <td class="oj-table-data-cell oj-form-control-inherit">
                            @item.QuequedDate
                        </td>
                        <td class="oj-table-data-cell oj-form-control-inherit">
                            @item.ElapsedTime
                        </td>
                        <td class="oj-table-data-cell oj-form-control-inherit">
                            <span class="label label-@item.StatusType.ToCssClass()">
                                @item.StatusTitle
                            </span>
                        </td>
                        <td class="oj-table-data-cell oj-form-control-inherit">
                            <a id="viewDetails" class="oj-button-primary" href="@Url.Action(MVC.ModelRuns.View(item.ModelRunId))"
                               data-bind="ojComponent: {component: 'ojButton'}">View details</a>
                        </td>
                        @if (item.StatusType.Equals(StatusViewModel.Success))
                        {
                            <td class="oj-table-data-cell oj-form-control-inherit">
                                Download as
                                <a href="@Url.Action(MVC.ModelRuns.DownloadAsJson(item.ModelRunId))" target="_blank">
                                    .json
                                </a>
                                |
                                <a href="@Url.Action(MVC.ModelRuns.DownloadAsCsv(item.ModelRunId))" target="_blank">
                                    .csv
                                </a>
                            </td>
                        }
                    </tr>
                </tbody>
            }
        </table>
    }
    else
    {
        <div class="panel panel-default">
            <div class="panel-body">
                <p>
                    We don't have any model run in SDCloud for this model
                </p>
            </div>
        </div>
    }
</div>